package com.engine4cloud.tdf.supervision.controller.web;

import com.engine4cloud.tdf.supervision.service.JzdxPreviewService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.OutputStream;

/**
 * 矫正对象-信息预览-web
 *
 * @author wenjie
 * @date 2024-03-14 11:20:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/web/corrector/preview")
@Tag(description = "CorrectorPreviewWeb", name = "矫正对象-信息预览-web")
public class JzdxPreviewWebController {

    @Resource
    private JzdxPreviewService previewService;

    /**
     * 后面这些接口可以全部拿出来单独成模块
     *
     * @param code 矫正对象编号
     */
    @Operation(summary = "基本信息预览", description = "基本信息预览")
    @GetMapping(value = "/{code}", produces = {MediaType.APPLICATION_OCTET_STREAM_VALUE})
    public void preview(@Schema(description = "矫正对象编号") @PathVariable("code") String code, HttpServletResponse response) throws IOException {
        // 获取响应输出流
        try (OutputStream os = response.getOutputStream()) {
            os.write(previewService.preview(code));
            os.flush();
        }
    }
}
